package com.xiaozhou.controller;

import com.zhipu.oapi.ClientV4;
import com.zhipu.oapi.service.v4.image.CreateImageRequest;
import com.zhipu.oapi.service.v4.image.ImageApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shhzhou
 * @description: 文生图 例子
 * @date 2024/10/31 15:52
 */
@RestController
@RequestMapping("/image")
public class ImageController {

    @Autowired
    private ClientV4 clientV4;

    @GetMapping("/model")
    public ImageApiResponse model(String message) {
        // 构建图片请求参数
        CreateImageRequest request = CreateImageRequest.builder()
                .model("cogview-3-plus")
                .prompt(message)
                .build();

        ImageApiResponse image = clientV4.createImage(request);
        return image;
    }
}
